home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / c / cweb31p9d.lha / CWeb / comm-p.h < prev    next >
C/C++ Source or Header  |  1994-07-02  |  13KB  |  290 lines

  1. % This file, common.h, is part of CWEB.
  2. % This program by Silvio Levy and Donald E. Knuth
  3. % is based on a program by Knuth.
  4. % It is distributed WITHOUT ANY WARRANTY, express or implied.
  5. % Version 2.1 -- Don Knuth, January 1992
  6. % Version 2.1 [p5] --- Hans-Hermann Bode, July 1992
  7. % Version 2.1 [p5a] --- Klaus Guntermann, July 1992
  8. % Version 2.1 [p5b] --- Hans-Hermann Bode, July 1992
  9. % Version 2.1 [p6] --- Hans-Hermann Bode, September 1992
  10. % Version 2.1 [p6a] --- Andreas Scherer, March 1993
  11. % Version 2.1 [p6b] --- Andreas Scherer, July 1993
  12. % Version 2.1 [p6c] --- Andreas Scherer, September 1993
  13. % Version 2.8 --- Don Knuth, September 1992
  14. % Version 2.8 [p7] --- Andreas Scherer, October 1993
  15. % Version 3.0 --- Don Knuth, June 1993
  16. % Version 3.0 [p8c] --- Hans-Hermann Bode, June 1993
  17. % Version 3.0 [p8d] --- Andreas Scherer, October 1993
  18. % Version 3.0 [p8e] --- Andreas Scherer, November 1993
  19. % Version 3.1 [p9] --- Andreas Scherer, November 1993
  20. % Version 3.1 [p9a] --- Andreas Scherer, November 1993
  21. % Version 3.1 [p9b] --- Andreas Scherer, December 1993
  22. % Version 3.1 [p9c] --- Andreas Scherer, January 1994
  23. % Version 3.1 [p9d] --- Andreas Scherer, July 1994
  24.  
  25. % Copyright (C) 1987,1990,1993 Silvio Levy and Donald E. Knuth
  26. % Copyright (C) 1991-1993 Hans-Hermann Bode
  27. % Copyright (C) 1991,1993 Carsten Steger
  28. % Copyright (C) 1993,1994 Andreas Scherer
  29.  
  30. % Permission is granted to make and distribute verbatim copies of this
  31. % document provided that the copyright notice and this permission notice
  32. % are preserved on all copies.
  33.  
  34. % Permission is granted to copy and distribute modified versions of this
  35. % document under the conditions for verbatim copying, provided that the
  36. % entire resulting derived work is distributed under the terms of a
  37. % permission notice identical to this one.
  38.  
  39. % Please send comments, suggestions, etc. to levy@@geom.umn.edu.
  40. % If related to changes specific for MSDOS, however,
  41. % send them to Hans-Hermann Bode,
  42. % hhbode@@dosuni1.rz.uni-osnabrueck.de or HHBODE@@DOSUNI1.BITNET.
  43. % If related to changes specific for AMIGA, however,
  44. % send them to Andreas Scherer,
  45. % Abt-Wolf-Straße 17, 96215 Lichtenfels, Germany.
  46.  
  47. % The next few sections contain stuff from the file |"common.w"| that has
  48. % to be included in both |"ctangle.w"| and |"cweave.w"|. It appears in this
  49. % file |"common.h"|, which needs to be updated when |"common.w"| changes.
  50.  
  51. First comes general stuff.
  52. In {\mc TURBO} \CEE/, we use |huge| pointers instead of large arrays.
  53. @^system dependencies@>
  54.  
  55. @f far int
  56. @f huge int
  57. @f HUGE int
  58. @#
  59. @d ctangle 0
  60. @d cweave 1
  61.  
  62. @<Common code for \.{CWEAVE} and \.{CTANGLE}@>=
  63. typedef short boolean;
  64. typedef char unsigned eight_bits;
  65. extern boolean program; /* \.{CWEAVE} or \.{CTANGLE}? */
  66. extern int phase; /* which phase are we in? */
  67. @#
  68. #ifdef __TURBOC__
  69. #define HUGE huge
  70. #else
  71. #define HUGE
  72. #endif
  73. @^system dependencies@>
  74.  
  75. @ Version~2.1 of the {\mc AMIGA} operating system introduced localization
  76. of programs and applications by means of ``language catalogs'' that contain
  77. replacement strings for terminal texts produced by suitably prepared programs.
  78. The complete \.{CWEB} system has been modified to accommodate this great idea
  79. and so the \.{cweb.h} header file with the original English strings is
  80. included in this section.  Other systems than the {\mc AMIGA} will have to do
  81. the language conversion by different means, so a little bit of care is to be
  82. taken with what follows.
  83. @^system dependencies@>
  84.  
  85. @f type int /* Aus \.{type} wird der Pseudotyp \&{type} */
  86. @#
  87. @d alloc_object(object,size,@!type)
  88.    if(!(object = (type *)calloc(size,sizeof(type))))
  89.       fatal("",get_string(MSG_FATAL_CO85));
  90.  
  91. @<Include files@>=
  92. #include <stdio.h>
  93. @#
  94. #ifdef __TURBOC__
  95. #include <io.h>
  96. #endif
  97. @#
  98. #ifndef _AMIGA /* non-{\mc AMIGA} systems don't know about \.{<exec/types.h>} */
  99. typedef long int LONG; /* excerpt from \.{<exec/types.h>} */
  100. typedef char * STRPTR; /* ditto, but \UNIX/ says it's signed. */
  101. #define EXEC_TYPES_H 1 /* don't include \.{<exec/types.h>} in \.{"cweb.h"} */
  102. #endif
  103. @#
  104. #ifdef STRINGARRAY
  105. #undef STRINGARRAY /* don't include the string array |AppStrings| again */
  106. #endif
  107. #define get_string(n) AppStrings[n].as_Str
  108. @#
  109. #include "cweb.h"
  110. @#
  111. struct AppString
  112. {
  113.    LONG   as_ID;
  114.    STRPTR as_Str;
  115. };
  116. @#
  117. extern struct AppString AppStrings[];
  118.  
  119. @ Code related to the character set:
  120. @^ASCII code dependencies@>
  121.  
  122. @d and_and 04 /* `\.{\&\&}'\,; corresponds to MIT's {\tentex\char'4} */
  123. @d lt_lt 020 /* `\.{<<}'\,;  corresponds to MIT's {\tentex\char'20} */
  124. @d gt_gt 021 /* `\.{>>}'\,;  corresponds to MIT's {\tentex\char'21} */
  125. @d plus_plus 013 /* `\.{++}'\,;  corresponds to MIT's {\tentex\char'13} */
  126. @d minus_minus 01 /* `\.{--}'\,;  corresponds to MIT's {\tentex\char'1} */
  127. @d minus_gt 031 /* `\.{->}'\,;  corresponds to MIT's {\tentex\char'31} */
  128. @d not_eq 032 /* `\.{!=}'\,;  corresponds to MIT's {\tentex\char'32} */
  129. @d lt_eq 034 /* `\.{<=}'\,;  corresponds to MIT's {\tentex\char'34} */
  130. @d gt_eq 035 /* `\.{>=}'\,;  corresponds to MIT's {\tentex\char'35} */
  131. @d eq_eq 036 /* `\.{==}'\,;  corresponds to MIT's {\tentex\char'36} */
  132. @d or_or 037 /* `\.{\v\v}'\,;  corresponds to MIT's {\tentex\char'37} */
  133. @d dot_dot_dot 016 /* `\.{...}'\,;  corresponds to MIT's {\tentex\char'16} */
  134. @d colon_colon 06 /* `\.{::}'\,;  corresponds to MIT's {\tentex\char'6} */
  135. @d period_ast 026 /* `\.{.*}'\,;  corresponds to MIT's {\tentex\char'26} */
  136. @d minus_gt_ast 027 /* `\.{->*}'\,;  corresponds to MIT's {\tentex\char'27} */
  137.  
  138. @<Common code...@>=
  139. char *section_text; /* name being sought for */
  140. char *section_text_end; /* end of |section_text| */
  141. char *id_first; /* where the current identifier begins in the buffer */
  142. char *id_loc; /* just after the current identifier in the buffer */
  143.  
  144. @ Code related to input routines:
  145.  
  146. @d xisalpha(c) (isalpha(c)&&((eight_bits)c<0200))
  147. @d xisdigit(c) (isdigit(c)&&((eight_bits)c<0200))
  148. @d xisspace(c) (isspace(c)&&((eight_bits)c<0200))
  149. @d xislower(c) (islower(c)&&((eight_bits)c<0200))
  150. @d xisupper(c) (isupper(c)&&((eight_bits)c<0200))
  151. @d xisxdigit(c) (isxdigit(c)&&((eight_bits)c<0200))
  152.  
  153. @<Common code...@>=
  154. extern char *buffer; /* where each line of input goes */
  155. extern char *buffer_end; /* end of |buffer| */
  156. extern char *loc; /* points to the next character to be read from the buffer*/
  157. extern char *limit; /* points to the last character in the buffer */
  158.  
  159. @ Code related to identifier and section name storage:
  160. @d length(c) (size_t)((c+1)->byte_start-(c)->byte_start) /* the length of a name */
  161. @d print_id(c) term_write((c)->byte_start,length((c))) /* print identifier */
  162. @d llink link /* left link in binary search tree for section names */
  163. @d rlink dummy.Rlink /* right link in binary search tree for section names */
  164. @d root name_dir->rlink /* the root of the binary search tree
  165.   for section names */
  166. @d chunk_marker 0
  167.  
  168. @<Common code...@>=
  169. typedef struct name_info {
  170.   char HUGE *byte_start; /* beginning of the name in |byte_mem| */
  171.   struct name_info HUGE *link;
  172.   union {
  173.     struct name_info HUGE *Rlink; /* right link in binary search tree for section
  174.       names */
  175.     char Ilk; /* used by identifiers in \.{WEAVE} only */
  176.   } dummy;
  177.   void HUGE *equiv_or_xref; /* info corresponding to names */
  178. } name_info; /* contains information about an identifier or section name */
  179. typedef name_info HUGE *name_pointer; /* pointer into array of |name_info|s */
  180. typedef name_pointer *hash_pointer;
  181. extern char HUGE *byte_mem; /* characters of names */
  182. extern name_info HUGE *name_dir; /* information about names */
  183. extern char HUGE *byte_mem_end; /* end of |byte_mem| */
  184. extern name_pointer name_dir_end; /* end of |name_dir| */
  185. extern name_pointer name_ptr; /* first unused position in |byte_start| */
  186. extern char HUGE *byte_ptr; /* first unused position in |byte_mem| */
  187. #ifdef __TURBOC__
  188. void far *allocsafe(unsigned long nunits,unsigned long unitsz);
  189. #endif
  190. @^system dependencies@>
  191. extern name_pointer *hash; /* heads of hash lists */
  192. extern hash_pointer hash_end; /* end of |hash| */
  193. extern hash_pointer h; /* index into hash-head array */
  194. extern int names_match(name_pointer,char *,int,eight_bits);@/
  195. extern name_pointer id_lookup(char *,char *,char);
  196.    /* looks up a string in the identifier table */
  197. extern name_pointer prefix_lookup(char *,char *); /* finds section name given a prefix */
  198. extern name_pointer section_lookup(char *,char *,int);@/
  199. extern void init_node(name_pointer);@/
  200. extern void init_p(name_pointer,eight_bits);@/
  201. extern void print_prefix_name(name_pointer);@/
  202. extern void print_section_name(name_pointer);@/
  203. extern void sprint_section_name(char *,name_pointer);@/
  204.  
  205. @ Code related to error handling:
  206. @d spotless 0 /* |history| value for normal jobs */
  207. @d harmless_message 1 /* |history| value when non-serious info was printed */
  208. @d error_message 2 /* |history| value when an error was noted */
  209. @d fatal_message 3 /* |history| value when we had to stop prematurely */
  210. @d mark_harmless {if (history==spotless) history=harmless_message;}
  211. @d mark_error history=error_message
  212. @d confusion(s) fatal(get_string(MSG_FATAL_CO66),s)
  213.  
  214. @<Common...@>=
  215. extern history; /* indicates how bad this run was */
  216. extern int wrap_up(void); /* indicate |history| and exit */
  217. extern void err_print(char *); /* prints error message and context */
  218. extern void fatal(char *,char *); /* issue error message and die */
  219. extern void overflow(char *); /* succumb because a table has overflowed */
  220.  
  221. @ Code related to file handling:
  222. @f line x /* make |line| an unreserved word */
  223. @d max_file_name_length 256
  224. @d cur_file file[include_depth] /* current file */
  225. @d cur_file_name file_name[include_depth] /* current file name */
  226. @d web_file_name file_name[0] /* main source file name */
  227. @d cur_line line[include_depth] /* number of current line in current file */
  228.  
  229. @<Common code...@>=
  230. extern include_depth; /* current level of nesting */
  231. extern FILE **file; /* stack of non-change files */
  232. extern FILE *change_file; /* change file */
  233. extern char *C_file_name; /* name of |C_file| */
  234. extern char *tex_file_name; /* name of |tex_file| */
  235. extern char *idx_file_name; /* name of |idx_file| */
  236. extern char *scn_file_name; /* name of |scn_file| */
  237. extern char **file_name; /* stack of non-change file names */
  238. extern char *change_file_name; /* name of change file */
  239. extern int *line; /* number of current line in the stacked files */
  240. extern change_line; /* number of current line in change file */
  241. extern boolean input_has_ended; /* if there is no more input */
  242. extern boolean changing; /* if the current line is from |change_file| */
  243. extern boolean web_file_open; /* if the web file is being read */
  244. extern boolean get_line(void); /* inputs the next line */
  245. extern void check_complete(void); /* checks that all changes were picked up */
  246. extern void reset_input(void); /* initialize to read the web file and change file */
  247.  
  248. @ Code related to section numbers:
  249. @<Common code...@>=
  250. typedef unsigned short sixteen_bits;
  251. extern sixteen_bits section_count; /* the current section number */
  252. extern boolean *changed_section; /* is the section changed? */
  253. extern boolean change_pending; /* is a decision about change still unclear? */
  254. extern boolean print_where; /* tells \.{CTANGLE} to print line and file info */
  255.  
  256. @ Code related to command line arguments:
  257. @d show_banner flags['b'] /* should the banner line be printed? */
  258. @d show_happiness flags['h'] /* should lack of errors be announced? */
  259. @d show_progress flags['p'] /* should progress reports be printed? */
  260. @d use_amiga_keywords flags['a'] /* should {\mc AMIGA/SAS C} keywords be used? */
  261. @d use_german_macros flags['g'] /* should the output be German? */
  262. @d indent_param_decl flags['i'] /* should formal parameter declarations be indented? */
  263. @d order_decl_stmt flags['o'] /* should declarations and statements be separated? */
  264. @d send_error_messages flags['m'] /* should {\mc AREXX} communication be used? */
  265.  
  266. @<Common code...@>=
  267. extern int argc; /* copy of |ac| parameter to |main| */
  268. extern char **argv; /* copy of |av| parameter to |main| */
  269. extern boolean flags[]; /* an option for each 8-bit code */
  270.  
  271. @ Code relating to output:
  272. @d update_terminal fflush(stdout) /* empty the terminal output buffer */
  273. @d new_line putchar('\n') @d putxchar putchar
  274. @d term_write(a,b) fflush(stdout),fwrite(a,sizeof(char),b,stdout)
  275. @d C_printf(c,a) fprintf(C_file,c,a)
  276. @d C_putc(c) putc(c,C_file)
  277.  
  278. @<Common code...@>=
  279. extern FILE *C_file; /* where output of \.{CTANGLE} goes */
  280. extern FILE *tex_file; /* where output of \.{CWEAVE} goes */
  281. extern FILE *idx_file; /* where index from \.{CWEAVE} goes */
  282. extern FILE *scn_file; /* where list of sections from \.{CWEAVE} goes */
  283. extern FILE *active_file; /* currently active file for \.{CWEAVE} output */
  284.  
  285. @ The procedure that gets everything rolling:
  286.  
  287. @<Common code...@>=
  288. extern void common_init(void);
  289. extern void print_stats(void);
  290.